//
//  SettingUserMessageTableViewCell.m
//  much
//
//  Created by Believer Just on 2019/1/9.
//  Copyright © 2019年 iOS. All rights reserved.
//

#import "SettingUserMessageTableViewCell.h"

@interface SettingUserMessageTableViewCell ()

/** 标题 */
@property (nonatomic, strong) UILabel *titleLabel;
/** 描述 */
@property (nonatomic, strong) UILabel *describeLabel;
/** 右箭头图片 */
@property (nonatomic, strong) UIImageView *rightArrowImageView;
@property (nonatomic, strong) UIView *lineView;

@end

@implementation SettingUserMessageTableViewCell

+ (instancetype)initTableView:(UITableView *)tableView {
    SettingUserMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([SettingUserMessageTableViewCell class])];
    if (!cell) {
        cell = [[SettingUserMessageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([SettingUserMessageTableViewCell class])];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
}


#pragma mark - method


#pragma mark - setting
- (void)setDic:(NSMutableDictionary *)dic {
    _dic = dic;
    
    self.titleLabel.text = _dic[CellTitle];
    self.describeLabel.text = _dic[CellDecribe];
    self.lineView.hidden =! [_dic[CellShowLine] boolValue];
}


#pragma mark - 懒加载
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.textColor = Color34;
        _titleLabel.font = APPFONT(14);
        _titleLabel.textAlignment = NSTextAlignmentLeft;
        [self.contentView addSubview:_titleLabel];
        [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).with.offset(15);
            make.centerY.equalTo(self.contentView);
        }];
    }
    return _titleLabel;
}
- (UILabel *)describeLabel {
    if (!_describeLabel) {
        _describeLabel = [UILabel new];
        _describeLabel.textColor = Color34;
        _describeLabel.font = APPFONT(14);
        _describeLabel.textAlignment = NSTextAlignmentRight;
        [self.contentView addSubview:_describeLabel];
        [_describeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.rightArrowImageView.mas_left).with.offset(- 10);
            make.centerY.equalTo(self.rightArrowImageView);
            make.left.equalTo(self.titleLabel.mas_right).with.offset(10);
        }];
    }
    return _describeLabel;
}
- (UIImageView *)rightArrowImageView {
    if (!_rightArrowImageView) {
        _rightArrowImageView = [UIImageView new];
        UIImage *image = IMAGE_NAME(@"user_home_sectionRightArrow");
        [_rightArrowImageView setImage:image];
        [self.contentView addSubview:_rightArrowImageView];
        [_rightArrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(self.contentView).with.offset(- 15);
            make.centerY.equalTo(self.contentView);
            make.width.mas_equalTo(image.size.width);
            make.height.mas_equalTo(image.size.height);
        }];
    }
    return _rightArrowImageView;
}
- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = Color217;
        [self.contentView addSubview:_lineView];
        [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).with.offset(15);
            make.right.equalTo(self.contentView).with.offset(- 15);
            make.bottom.equalTo(self.contentView);
            make.height.mas_equalTo(1);
        }];
    }
    return _lineView;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
